﻿using System.Diagnostics;

namespace MikadoShooter
{
    public class LevelMessageBox
    {
        public string Text { get; private set; }
        private readonly Stopwatch boxTime;
        private bool isNeedNewBuffer;
        private bool isNeedRenderTexture;
        private bool isMessage;

        public LevelMessageBox()
        {
            boxTime = new Stopwatch();
        }

        public bool IsNeedNewBuffer
        {
            get
            {
                if (isNeedNewBuffer)
                {
                    isNeedNewBuffer = false;
                    return true;
                }
                return false;
            }
            set
            {
                isNeedNewBuffer = value;
            }
        }

        public bool IsNeedRenderTexture()
        {
            if (isNeedRenderTexture)
            {
                isNeedRenderTexture = false;
                return true;
            }
            return false;
        }

        public void NewMessage(string format, params object[] arg)
        {
            isMessage = true;
            Text = string.Format(format,arg);
        }
        /*
        public void NewMessage(string text)
        {
            isMessage = true;
            Text = text;
        }
        */
        public bool IsMessage()
        {
            if (isMessage)
            {
                if (!boxTime.IsRunning)
                {
                    isNeedRenderTexture = true;
                    boxTime.Start();
                }

                if (boxTime.ElapsedMilliseconds >= 5000)
                {
                    Text = string.Empty;
                    isMessage = false;

                    boxTime.Reset();
                    return false;
                }

                return true;
            }
            return false;
        }
    }
}